package com.itheima.edu.info.manager.service;

import com.itheima.edu.info.manager.dao.StudentDao;
import com.itheima.edu.info.manager.domain.Student;

public class StudentService {
    private StudentDao stuDao = new StudentDao();

    public void remove() {

    }

    public void updateStudent(int index, Student student) {
        stuDao.updateStudent(index, student);
    }

    public boolean addStudent(Student stu) {
        // 创建Student对象
        // 调用stuDao里面的addStudent方法
        return stuDao.addStudent(stu);
    }

    public int isExists(String id) {
        // 假设id不存在数组
        int index = -1;
        Student[] students = stuDao.findAllStudent();
        for (int i = 0; i < students.length; i++) {
            if (students[i] != null && students[i].getId().equals(id)) {
                return i;
            }
        }
        return -1;
    }

    public Student[] findStudent() {
        Student[] allStudent = stuDao.findAllStudent();
        for (int i = 0; i < allStudent.length; i++) {
            if (allStudent[i] != null){
                return allStudent;
            }
        }
        return null;
    }

    public void remove(int id) {
        stuDao.remove(id);
    }
}
